<template>
	<view class="content">

		<!-- 查询 -->
		<view class="query">
			<view class="logo">
				<image src="https://friend.tanshishang.cn/assets/img/LOGO1.png" mode="aspectFit"></image>
			</view>
			<input type="number" maxlength="3" @blur="queryBlur" @confirm="queryConfirm" placeholder="请输入想要查询的臂贴号(如001)" >
			<button type="default" :disabled="disabled" @tap="doResult">提交</button>
		</view>

	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		computed: {
			...mapState(['token', 'userId'])
		},
		data() {
			return {
				//活动id
				id: '',
				queryNum: '',
				disabled: false,
			};
		},
		onLoad(data) {
			if (data.scene) {
				this.id = data.scene;
			}
		},
		onShow() {
			console.log('token:' + this.token);
			// if (!this.token) {
			// 	uni.showModal({
			// 		title: '您还未登录',
			// 		content: '点击登录,登录后可查看更多!',
			// 		showCancel: true,
			// 		confirmText: '登录',
			// 		success: (res) => {
			// 			// console.log(res);
			// 			if (res.confirm) {
			// 				uni.navigateTo({
			// 					url: "/pages/index/wxLogin"
			// 				})
			// 			} else if (res.cancel) {
			// 				console.log('用户点击取消');
			// 			}

			// 		}
			// 	});
			// }
		},
		methods: {
			async doResult() {
				if (this.queryNum) {
					console.log(this.queryNum);
					try {
						let params = {
							token: this.token,
							userId: this.userId,
							activeId: this.id,
							num: this.queryNum
						}
						let res = await this.$request.request.get('/api/wechat/search', params);
						if (res.code == 200) {
							//页面跳转到详情页
							if (res.data.gender == 1) {
								//男
								uni.navigateTo({
									url: '/pages/recommend/personal?type=0&from=query&id=' + res.data.userId
								})
							} else {
								//女
								uni.navigateTo({
									url: '/pages/recommend/personal?type=1&from=query&id=' + res.data.userId
								})
							}
						}
					} catch (err) {
						this.$request.error(err, this)
					}
				} else {
					uni.showToast({
						title: '请输入要查询的臂贴号!',
						icon: 'none',
						mask: true
					});
				}
			},
			//查询
			queryBlur(event) {
				// console.log(event.detail);
				event.detail.value.replace(/\s+/g, "") ? this.queryNum = event.detail.value.replace(/\s+/g, "") : this.queryNum = '';
			},
			queryConfirm(event) {
				// console.log(event.detail);
				event.detail.value.replace(/\s+/g, "") ? this.queryNum = event.detail.value.replace(/\s+/g, "") : this.queryNum = '';
			}
		}
	}
</script>

<style lang="scss">
	@import 'query.scss'
</style>
